<!DOCTYPE html>
<html>
<head>
<#include "../common/head.ftl">
</head>

<body>
<div class="wrapper2">
    <form class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-1 control-label">用户名</label>
            <div class="col-sm-3 required"><input value="${dto.m.account}" type="text" id="account" class="form-control" name="account" maxlength="20" readonly></div>
            <label class="col-sm-1 control-label">姓名</label>
            <div class="col-sm-3 required"><input type="text" class="form-control" name="name" maxlength="10"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-1 control-label">性别</label>
            <div class="col-sm-2">
                <label class="radio-inline"> <input type="radio" name="sex" value="1" checked="checked"> 男</label>
                <label class="radio-inline"> <input type="radio" name="sex" value="0"> 女</label>
            </div>
            <label class="col-sm-1 control-label">联系电话</label>
            <div class="col-sm-3"><input value="${(dto.m.telephone)!""}" type="text" class="form-control" name="telephone" maxlength="20"></div>
            <label class="col-sm-1 control-label">邮箱</label>
            <div class="col-sm-4"><input value="${dto.m.email}" type="email" class="form-control" name="email" maxlength="50"></div>
        </div>
        <div class="form-group form-btn-group">
            <div class="col-sm-12 text-right">
                <button type="submit" class="btn btn-primary">确认</button>
                <button type="button" id="cancel_btn" class="btn btn-default">取消</button>
            </div>
        </div>
    </form>
</div>
</body>
<#include "../common/scripts.ftl">
<script type="text/javascript">
    var pwin = window.pwin;
    $("#cancel_btn").on("click",function(){
        pwin.layer.closeAll();
    });
    $(".form-horizontal").validate({
        rules : {
            name:{required:true,isNormalName:true},
            password:{isUserName:true},
            tel:{required:true,isSim:true},
            email:{email:true}
        },
        messages : {
        },
        submitHandler : function(form) {
            var $btn =  $("button[type='submit']",$(form));
            var oldText = $btn.text();
            $btn.prop("disabled",true).html("<span class='fa fa-spinner fa-pulse'></span> 正在提交...");
            var comp = $(".form-horizontal").serializeObject();
            $.ajax({
                url : "sys_user/edit",
                type : "POST",
                contentType : "application/json;charset=utf-8",
                dataType : "json",
                data: JSON.stringify({m:comp}),
                success : function(data) {
                    if(data.success){
                        pwin.layer.closeAll();
                        pwin.grid.jqGrid().trigger("reloadGrid");
                        pwin.layer.msg(data.message);
                    }else{
                        layer.msg(data.message);
                        $btn.prop("disabled",false).text(oldText);
                    }
                },
                error: function () {
                    layer.msg("操作失败，请稍后重试");
                    $btn.prop("disabled",false).text(oldText);
                }
            });
        }
    });


</script>
</html>